package main.java.com.zheng.coderepo.permission;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zcz on 16-3-15.
 */
public class PermissionSubject {

    private List<Permission> permissions = new ArrayList<Permission>();

    public boolean isPermitted(String permissionName) {
        for (Permission permission : permissions) {
            if (permission.isPermitted(permissionName)) {
                return true;
            }
        }
        return false;
    }

    public boolean[] isPermitted(String... permissionNames) {
        if (permissionNames == null || permissionNames.length == 0) {
            return new boolean[0];
        }
        boolean[] result = new boolean[permissionNames.length];
        for (int i = 0; i < permissionNames.length; i++) {
            result[i] = isPermitted(permissionNames[i]);
        }
        return result;
    }

    public List<Permission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<Permission> permissions) {
        this.permissions = permissions;
    }

    public void addPermission(Permission permission) {
        if (permissions == null) {
            permissions = new ArrayList<Permission>();
        }
        permissions.add(permission);
    }
}
